package serivce;

import dao.FangZhiDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import untity.BriefHouse;
import untity.FangZhi;
import untity.Position;
import untity.UserConnection;
import untity.screen.Screen;

import java.util.List;

@Service
public class HoueImp implements House {

    @Autowired
    private FangZhiDao fangzhiDao;
    @Override
    public String addHouser(FangZhi fangZhi) {
        Integer b=fangzhiDao.add(fangZhi);
        return b.toString();
    }

    @Override
    public boolean setPosition(Position position) {
        fangzhiDao.setPosition(position);
        return false;
    }

    @Override
    public boolean putImg(String id, String[] path) {
        boolean b=fangzhiDao.putImg(id,path);
        return b;
    }

    @Override
    public int addEquipment(String id, List<String> list) {
        int num=fangzhiDao.addEquipment(id,list);
        return num;
    }

    @Override
    public List<BriefHouse> screen(Position position, Screen screen) {
        List<BriefHouse> list= fangzhiDao.screen(position,screen);
        return list;
    }

    @Override
    public String[] searchImg(int id) {
        String[] imgs=fangzhiDao.searchImg(id);
        return imgs;
    }

    @Override
    public FangZhi getHouseById(int id) {
        FangZhi f=fangzhiDao.getFangZhi(id);
        f.setPicture(fangzhiDao.allImg(id));
        f.setPosition(fangzhiDao.seachPositionById(id));
        return f;
    }

    @Override
    public List<BriefHouse> nearbyHouse(Position position) {
        List<BriefHouse> list=fangzhiDao.nearbyHouse(position);
        String imgpath=null;
        for (BriefHouse b:list){
            if (fangzhiDao.searchImg(b.getId()).length!=0){
                imgpath=fangzhiDao.searchImg(b.getId())[0];
            }else {
                imgpath=null;
            }
            b.setImgPath(imgpath);
        }
        return list;
    }

    @Override
    public UserConnection queryByhouseID(String id) {
        UserConnection user= fangzhiDao.queryByhouseID(id);
        return user;
    }

    @Override
    public Boolean updateStatus(String houseId) {
        Boolean flag= fangzhiDao.updateStatus(houseId);
        return flag;
    }


}
